package com.aabte.auth.group.domain.event;

import com.aabte.auth.group.domain.model.GroupId;
import com.aabte.auth.group.domain.model.GroupName;
import com.aabte.commons.ddd.shared.DomainEvent;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;
import java.util.UUID;

@Getter
@ToString
public class GroupCreated implements DomainEvent<GroupCreated, String> {

    private final String eventId;
    private final GroupId groupId;
    private final GroupName groupName;

    public GroupCreated(GroupId groupId, GroupName groupName) {
        this.eventId = UUID.randomUUID().toString().replaceAll("-", "");
        this.groupId = groupId;
        this.groupName = groupName;
    }

    @Override
    public boolean sameIdentityAs(GroupCreated groupCreated) {
        return this.eventId.equals(groupCreated.eventId);
    }

    @Override
    public String identity() {
        return this.eventId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GroupCreated that = (GroupCreated) o;
        return eventId.equals(that.eventId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(eventId);
    }
}
